package network.UDPTest;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpSendDemo01 {
    public static void main(String[] args) throws IOException {
        //1.建立Socket连接
        DatagramSocket socket = new DatagramSocket();
        //2.建个包
        String msg = "您好Java";
        InetAddress localhost = InetAddress.getByName("localhost");
        int port = 9090;

        //数据，数据长度起始，发给谁
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, localhost, port);

        //3.发送包
        socket.send(packet);
        //4.关闭流
        socket.close();
    }
}
